#include <iostream>

using namespace std;

#include "list_of_cuts2.h"


void print_cuts(list_of_cuts * p){
  if(p != NULL){
    std::cout<<"Struct max cuts: "<< p->number_of_cuts << " Current: " << p->cuts_added <<"\n";
    for(int i = 0; i < p->cuts_added;i++){
      std::cout << "C" << i << ": ";
      for(int j = 0; j<p->nz[i];j++){
	std::cout << (p->cut_idx_arrays[i][j])*p->cut_val_arrays[i][j] << " ";
      }
      std::cout << " <= " << p->rhs[i] << "\t nz: " << p->nz[i] <<  std::endl;
    }
  }
}


list_of_cuts *  init_cut_struct(int num_cuts){
  list_of_cuts * p = new list_of_cuts;
  p->number_of_cuts = num_cuts;
  p->cuts_added = 0;
  return p;
}

void add_cut_struct(list_of_cuts * l, double rhs, int nz, vector<int>& idx_array, vector<double>& val_array){

  l->rhs.push_back(rhs);
  l->nz.push_back(nz);
  l->cut_idx_arrays.push_back(idx_array);
  l->cut_val_arrays.push_back(val_array);
  l->cuts_added++;
  l->number_of_cuts++;  
}

void adjust_index(list_of_cuts * cuts, const int offset){
  if(cuts != NULL){
    for(int i = 0; i <cuts->cuts_added;i++){
      for(int j = 0; j<cuts->nz[i];j++){
	cuts->cut_idx_arrays[i][j] += offset;
      }
    }
  }
}

void clear_cuts(list_of_cuts* l){
  if(l != NULL){
    l->rhs.clear();
    l->nz.clear();
    for(unsigned int i = 0; i<l->cut_idx_arrays.size(); ++i){
      l->cut_idx_arrays[i].clear();
      l->cut_val_arrays[i].clear();
    }

    l->cut_idx_arrays.clear();
    l->cut_val_arrays.clear();
    l->cuts_added = 0;
    l->number_of_cuts = 0;
    delete l;
  }
}
